import { reqCategoryList, reqGetBannerList,reqGetFloorList} from "@/api";
//home模块小仓库
const state = {
    categoryList: [],   //根据服务器返回值初始化
    bannerList: [], //轮播图数据
    floorList: []
};
const mutations = {
    CATEGORYLIST(state,categoryList) {
        state.categoryList = categoryList;
    },
    GETBANNERLIST(state,bannerList) {
        state.bannerList = bannerList;
    },
    GETFLOORLIST(state,floorList) {
        state.floorList = floorList;
    }
};
const actions = {
    //通过API里面的接口函数调用，向服务器发送请求，获取服务器数据
    async categoryList({commit}) {
        let reslut = await reqCategoryList();
        if(reslut.code == 200) {
            commit("CATEGORYLIST",reslut.data);
        }
    },
    async getBannerList({commit}) {
        let result = await reqGetBannerList();
        if(result.code == 200) {
            commit('GETBANNERLIST',result.data);
        }
    },
    async getFloorList({commit}) {
        let result = await reqGetFloorList();
        if(result.code == 200) {
            commit('GETFLOORLIST',result.data);
        }
    }
};
const getters = {};

export default {
    state,
    mutations,
    actions,
    getters
}